package com.lc202309;

import java.util.ArrayList;
import java.util.List;

/**
 * Description:
 *
 * @Create 2023/8/26 22:54
 * @Version 1.0
 */
public class Solution228 {
    public static List<String> summaryRanges(int[] nums) {
        List<String> list = new ArrayList<>();
        if (nums.length == 0) {
            return list;
        }
        int first = 0;
        int end = 0;
        for (int i = 0; i < nums.length; i++) {
            if (i == 0) {
                first = nums[i];
                end = nums[i];
                continue;
            }
            if ((end + 1) != nums[i]) {
                if (first == end) {
                    list.add(String.valueOf(first));
                } else {
                    list.add(first + "->" + end);
                }
                first = nums[i];
            }
            end = nums[i];
        }
        if (first == end) {
            list.add(String.valueOf(first));
        } else {
            list.add(first + "->" + end);
        }
        return list;
    }

    public static void main(String[] args) {
        int[] arrs = new int[]{0,1,2,4,5,7};
        System.out.println(summaryRanges(arrs));
    }
}
